package com.sahyadri.web.util.tags;

import java.io.IOException;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.SimpleTagSupport;

/**
 * The Class RatingTag.
 * 
 */
public class RatingTag extends SimpleTagSupport {

	
	private int rating;
	
	/* (non-Javadoc)
	 * @see javax.servlet.jsp.tagext.SimpleTagSupport#doTag()
	 */


	public void doTag() throws JspException, IOException {

		JspWriter out = getJspContext().getOut();  
	
    	StringBuffer script = new StringBuffer();

    	script.append(getStatusHtml());    	
    	
    	out.print(script);
        out.flush();
	}
	
	/**
	 * Gets the Html string for the status messages
	 * 
	 * @return the Javascript string for the status messages
	 */
	private String getStatusHtml()
	{
		String newline = System.getProperty("line.separator");
		StringBuffer script = new StringBuffer();
		for(int count = 1; count<=5; count++){
			if(count <= rating){
				script.append("<span class=\"rating-yes\"></span>");
			}else{
				script.append("<span class=\"rating-no\"></span>");
			}
		}
		
		
		script.append(newline);
		
		return(script.toString());
	}
	
	

	public int getRating() {
		return rating;
	}

	public void setRating(int rating) {
		this.rating = rating;
	}

	
	
	
}

